package cn.stylefeng.guns.modular.rest;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.modular.school.entity.StudentInfo;
import cn.stylefeng.guns.modular.school.entity.TeacherInfo;
import cn.stylefeng.guns.modular.school.model.params.ClassSchoolTableParam;
import cn.stylefeng.guns.modular.school.service.ClassSchoolTableService;
import cn.stylefeng.guns.modular.school.service.StudentInfoService;
import cn.stylefeng.guns.modular.school.service.TeacherInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


/**
 * 取得课表信息
 *
 * @author
 * @Date 2019-11-18 13:24:11
 */
@RestController
@RequestMapping("/gunsApi/class/school/table")
public class ApiNeedTokenClassSchoolTableController extends BaseController {

    @Autowired
    private StudentInfoService studentInfoService;
    @Autowired
    private ClassSchoolTableService classSchoolTableService;
    @Autowired
    private TeacherInfoService teacherInfoService;

    /**
     * 课表信息取得
     *
     * @param userId 当前用户id
     * @param type
     * @return
     */
    @RequestMapping(value = "list")
    public Object list(String userId, String type) {
        Map map = new HashMap();
        ClassSchoolTableParam param = new ClassSchoolTableParam();
        StudentInfo studentInfo = studentInfoService.findByCode(userId);
        if (studentInfo == null) {
            // 取得老师的课表
            //TeacherInfo teacherInfo = teacherInfoService.getOne(new QueryWrapper<TeacherInfo>().eq("code", userId));
            TeacherInfo teacherInfo = teacherInfoService.findByCode(userId);
            param.setTeacherId(teacherInfo.getId());
            map = classSchoolTableService.findTeacherSchoolTable(param);

        } else {
            Integer classId = studentInfo.getClassId();
            // 取学生课表
            param.setClassId(classId);
            param.setStudentInfo(studentInfo);
            map = classSchoolTableService.findStudentSchoolTable(param);
//
//            param.setType("1");
//            param.setClassId(classId);
//            List<ClassSchoolTableResult> classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            classSchoolTableResultList.forEach(classSchoolTableResult -> {
//                List<CourseSign> courseSigns = courseSignService.list(new QueryWrapper<CourseSign>().eq("sign_date", DateUtil.today()).eq("student_teacher_id", studentInfo.getId()).eq("school_table_id", classSchoolTableResult.getId()));
//                if (courseSigns.size() > 0) {
//                    classSchoolTableResult.setSigned(true);
//                }
//            });
//            map.put("monday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("2");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("tuesday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("3");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("wednesday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("4");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("thursday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("5");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("friday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("6");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("saturday", classSchoolTableResultList);
//
//            param = new ClassSchoolTableParam();
//            param.setType("7");
//            param.setClassId(classId);
//            classSchoolTableResultList = classSchoolTableService.findListByClassId(param);
//            map.put("sunday", classSchoolTableResultList);
        }


        // 周一2
        if (DateUtil.dayOfWeek(new DateTime()) == 2) {
            map.put("activeIndex", 0);
        }
        //周二是3，
        else if (DateUtil.dayOfWeek(new DateTime()) == 3) {
            map.put("activeIndex", 1);
        } else if (DateUtil.dayOfWeek(new DateTime()) == 4) {
            map.put("activeIndex", 2);
        } else if (DateUtil.dayOfWeek(new DateTime()) == 5) {
            map.put("activeIndex", 3);
        } else if (DateUtil.dayOfWeek(new DateTime()) == 6) {
            map.put("activeIndex", 4);
        } else if (DateUtil.dayOfWeek(new DateTime()) == 7) {
            map.put("activeIndex", 5);
        } else if (DateUtil.dayOfWeek(new DateTime()) == 1) {
            map.put("activeIndex", 6);
        }


        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

}


